<script>
	import Vue from 'vue'
	import { mapActions } from 'vuex'
	import { User } from '@/models/user.js';
	let user = new User()
	let __timerId = 0;
	export default {
	
		async onLaunch() {
			/**
			 * 存储设备信息
			 */
			this.$mTool.getBarHeight(systemInfo => {
				Vue.prototype.systemInfo = systemInfo;
			})
			user.getLocation()
			user.getTokenFromServer()
			await this.initLogin()
		},
		methods: {
			...mapActions(['appLogin']),
			//登录状态
			async initLogin(){
				
				return user.localtLogin().then().catch(errcode => {
					if(errcode != '996') return
					let loginMobile = uni.getStorageSync("loginMobile");
					if(!loginMobile) return ''
					User.reLogin(loginMobile).then(info => {
						if(info){
							this.appLogin(info)
						}
					});
				})
								
			},
			
			
			//打开全局定时器
			openTimer(){
				this.closeTimer();
				__timerId = setInterval(()=>{
					this.$store.commit('setStateAttr', {
						key: 'timerIdent',
						val: !this.$store.state.timerIdent
					})
				}, 1000)
			},
			//关闭定时器
			closeTimer(){
				if(__timerId != 0){
					clearInterval(__timerId);
					__timerId = 0;
				}
			},
		},
		onShow() {
			console.log('app show');
			// this.openTimer();
		},
		onHide() {
			// this.closeTimer();
		}
	}
</script>

<style lang='scss'>
	@import "/static/colorui/main.css";
	@import "/static/colorui/icon.css";
	@import "/static/colorui/common.css";
</style>


